<?php
/**
 * Created by PhpStorm.
 * User: sunwu
 * Date: 2018/2/5
 * Time: 15:30
 */

namespace app\home\model;

class User extends Base{
    protected $table='rs_user';
    protected $pk='PK_UserGuid';

    public function getUserInfo($guid='')
    {
        if($guid){
            $userId=$guid;
            $userInfo=self::with(['collection','resource','recomment','collection.resource','recomment.resource','downloads','downloads.resource'])->find($userId);
            return $userInfo;
        }
        $userId=session('uid');
        $userInfo=self::with(['collection','resource','recomment','collection.resource','recomment.resource','downloads','downloads.resource'])->find($userId);
        return $userInfo;
    }

    public function collection()
    {
        return $this->hasMany('collection','FK_UserGuid');
    }

    public function resource(){
        return $this->hasMany('resource','FK_UserGuid');
    }

    public function recomment()
    {
        return $this->hasMany('comment','FK_UserGuid');

    }

    public function downloads()
    {
        return $this->hasMany('downloads','FK_UserGuid');
    }
}